package ru.edu.vstu.atpp.acm.ui.services.dao.impl;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import ru.edu.vstu.atpp.acm.ui.entities.Tema;
import ru.edu.vstu.atpp.acm.ui.services.dao.TemaDAO;

import java.util.List;

public class TemaDAOImpl implements TemaDAO {

    @Inject
    private Session session;

    @Override
    public Tema getById(Long id) {
        return (Tema) session.get(Tema.class, id);
    }

    @Override
    public Tema getByName(String name) {
        return null;
    }

    @Override
    public List<Tema> getAll() {
        return null;
    }



    @Override
    public List<Tema> getChildren(Tema tema) {
        Criterion criterion = Restrictions.eq("tema", tema);
        return session.createCriteria(Tema.class).add(criterion).list();
    }

    @Override
    public List<Tema> getRootValues() {
        Criterion criterion = Restrictions.isNull("tema");
        return session.createCriteria(Tema.class).add(criterion).list();
    }

    @Override
    public void persist(Tema tema) {

    }
}
